package cn.com.gridinfo.sooc.core.expand.score.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder;
import com.marshalchen.ultimaterecyclerview.UltimateViewAdapter;

import java.util.List;

import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.core.expand.score.bean.MyInviteEntity;

/**
 * 我的邀请的列表适配器
 *
 * @author yingchunli
 */
public class MyInviteAdapter extends UltimateViewAdapter<MyInviteAdapter.ViewHolder> {

    public List<MyInviteEntity> myInviteList;
    Context context;

    public MyInviteAdapter(List<MyInviteEntity> myInviteList, Context context) {
        this.myInviteList = myInviteList;
        this.context = context;
    }

    @Override
    public ViewHolder getViewHolder(View view) {
        return new ViewHolder(view, false);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent) {
        //加载布局
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.expand_score_myinvite_item, parent, false);

        return new ViewHolder(view, true);
    }


    @Override
    public int getAdapterItemCount() {
        return myInviteList.size();
    }

    @Override
    public long generateHeaderId(int position) {
        return position;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (position < getItemCount() &&
                (customHeaderView != null ? position <= myInviteList.size() : position < myInviteList.size())
                && (customHeaderView != null ? position > 0 : true)) {
            MyInviteEntity myInviteEntity = myInviteList.get(position);
            holder.time.setText(myInviteEntity.getTime());
            holder.email.setText(myInviteEntity.getEmail());
            holder.nickname.setText(myInviteEntity.getName());

//            if (position == myInviteList.size() - 1) {
//                holder.line.setVisibility(View.VISIBLE);
//            } else {
//                holder.line.setVisibility(View.GONE);
//            }
        }
    }

    public void loadmore(List<MyInviteEntity> list) {
        myInviteList.addAll(list);
        notifyDataSetChanged();
    }

    public void refresh(List<MyInviteEntity> list) {
        myInviteList.clear();
        myInviteList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        return null;
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {

    }

    //ViewHolder
    public class ViewHolder extends UltimateRecyclerviewViewHolder {
        TextView time, email, nickname;
        View line;//底部分割线

        public ViewHolder(View itemView, boolean isItem) {
            super(itemView);
            if (isItem) {
                time = (TextView) itemView.findViewById(R.id.time_myinvite);
                email = (TextView) itemView.findViewById(R.id.email_myinvite);
                nickname = (TextView) itemView.findViewById(R.id.nickname_myinvite);
//                line = (View) itemView.findViewById(R.id.line_bottom);
            }
        }
    }
}
